<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            var time = new Date();
            console.log([time]);
            //获取年份
            var year = time.getFullYear();
            console.log(year);
            //获取月份
            var month = time.getMonth();
            console.log(month+1);
            //获取日期
            var date = time.getDate();
            console.log(date);
            //获取星期
            var day = time.getDay();
            console.log(day);
            //获取小时
            var hour = time.getHours();        
            console.log(hour);
            //获取分钟
            var minute = time.getMinutes();
            console.log(minute);
            //获取秒
            var second = time.getSeconds();
            console.log(second);
            //获取毫秒
            var millisecond = time.getMilliseconds();
            console.log(millisecond);
            //设置年份
            time.setFullYear(2018);
            console.log(time.getFullYear());
            //设置月份
            time.setMonth(6);
            console.log(time.getMonth());
            //设置日期
            time.setDate(1);
            console.log(time.getDate());

            var fn =function(){
                 var time = new Date();
                //获取年份
                var year = time.getFullYear();
                //获取月份
                var month = time.getMonth()+1;
                //获取日期
                var date = time.getDate();
                //获取小时
                var hour = time.getHours();
                //获取分钟
                var minute = time.getMinutes();
                //获取秒
                var second = time.getSeconds();
                document.body.innerHTML = year+'-'+month+'-'+date+' '+hour+':'+minute+':'+second;
            };
            setInterval(fn,1000);


        </script>
    </body>
</html>